#pragma once
#include "Interface.h"

class CWorkItem :public CAsyncSocket
{
public:
	CWorkItem();
	~CWorkItem(void);

	virtual void Close();

	bool Init(ICallBack	* pCallBack);
	int SendData(char* pBuf,int nLen);

	virtual BOOL DoConnect(LPCTSTR lpszHostAddress, UINT nHostPort);

protected:
	virtual void OnReceive(int nErrorCode);
	virtual void OnConnect(int nErrorCode);
	virtual void OnSend(int nErrorCode);
	virtual void OnAccept(int nErrorCode);
	virtual void OnClose(int nErrorCode);

	bool ReadHead(int &nBody);
	bool ParseHead(const char* pBuf, int & nPos);
	bool MakeHead(const string&);
	string GetHeadValue(const string&);

	bool GetChunkedLength(const char*,int&,int&);
	int GetTotalBuf(char* pBuf,int nLen);

private:
	ICallBack	* m_pCallBack;

	int m_nCount ;
	char * m_pRecvBuf ;


	CEvent m_hEvent;

	map<string,string> m_Head;
	int  m_nContentLength;

	int	m_nTotalReceived;

	TranferEncodeType m_nEncodeType;

	int m_nHeadLength;

	//int m_nBufUsed;
};
